<?php
class Vs_ReasonFamily_Mapper
    extends Vs_Mapper
	
{
    public function delete( $reasonFamily )
	{
		$mapper = Vs_Factory::mapper('Reason');
	 	$questions = $mapper->getByParams( array('reasonFamilyId' => $reasonFamily->getId()));
		
		if ( count($questions) ){
			throw new Vs_Exception ( Vs_Exception::REASONFAMILY_CANNOT_BE_DELETED );
		}
				
		$table= $this->getTable();
		
		return $table->delete( $reasonFamily );
	}
	
	public function loadReasons( $reasonFamilies )
	{
		$mapper = Vs_Factory::mapper('Reason');
	
		if ( $reasonFamilies instanceof Vs_ReasonFamily_Collection){
	
			if (count( $reasonFamilies ) < 1){
				return;
			}
			
			$reasons = $mapper->getByParams( array('reasonFamilyId' => $reasonFamilies->getIds()) );
				
			$reasonFamilies->setReasons($reasons);
		}
	
		elseif ( $reasonFamilies instanceof Vs_ReasonFamily){
				
			$reasons = $mapper->getByParams( array('reasonFamilyId' => $reasonFamilies->getId()) );
	
			$reasonFamilies->setReasons($reasons);
		}
	}
	
	
	
}
